package com.bst.md.service.impl;

import java.util.List;

import com.bst.md.domain.MdIndexSuffix;
import com.bst.md.service.IMdIndexSuffixService;
import com.bst.md.vo.MdIndexParamVO;
import com.bst.system.vo.IndexWallParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bst.md.mapper.MdIndexMapper;
import com.bst.md.domain.MdIndex;
import com.bst.md.service.IMdIndexService;
import com.bst.common.core.text.Convert;

/**
 * 指标信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-18
 */
@Service("indexService")
public class MdIndexServiceImpl implements IMdIndexService 
{
    @Autowired
    private MdIndexMapper mdIndexMapper;
    @Autowired
    IMdIndexSuffixService mdIndexSuffixService;

    /**
     * 查询指标信息
     * 
     * @param idIndex 指标信息主键
     * @return 指标信息
     */
    @Override
    public MdIndex selectMdIndexByIdIndex(String idIndex)
    {
        return mdIndexMapper.selectMdIndexByIdIndex(idIndex);
    }

    /**
     * 查询指标信息列表
     * 
     * @param mdIndex 指标信息
     * @return 指标信息
     */
    @Override
    public List<MdIndex> selectMdIndexList(MdIndex mdIndex)
    {
        return mdIndexMapper.selectMdIndexList(mdIndex);
    }

    /**
     * 新增指标信息
     * 
     * @param mdIndex 指标信息
     * @return 结果
     */
    @Override
    public int insertMdIndex(MdIndex mdIndex)
    {
        String cdSuffix = mdIndex.getCdSuffix();
        MdIndexSuffix suffix = new MdIndexSuffix();
        suffix.setCd(cdSuffix);
        List<MdIndexSuffix> suffixList = mdIndexSuffixService.selectMdIndexSuffixList(suffix);
        int num = 0;
        if(suffixList.size()>0) {
            suffix = suffixList.get(0);
            mdIndex.setSdValtp(suffix.getSdValtp());
            mdIndex.setFgAccu(suffix.getFgAccu());
            num = mdIndexMapper.insertMdIndex(mdIndex);
        }
        return num;
    }

    /**
     * 修改指标信息
     * 
     * @param mdIndex 指标信息
     * @return 结果
     */
    @Override
    public int updateMdIndex(MdIndex mdIndex)
    {
        return mdIndexMapper.updateMdIndex(mdIndex);
    }

    /**
     * 批量删除指标信息
     * 
     * @param idIndexs 需要删除的指标信息主键
     * @return 结果
     */
    @Override
    public int deleteMdIndexByIdIndexs(String idIndexs)
    {
        return mdIndexMapper.deleteMdIndexByIdIndexs(Convert.toStrArray(idIndexs));
    }

    /**
     * 删除指标信息信息
     * 
     * @param idIndex 指标信息主键
     * @return 结果
     */
    @Override
    public int deleteMdIndexByIdIndex(String idIndex)
    {
        return mdIndexMapper.deleteMdIndexByIdIndex(idIndex);
    }

    @Override
    public List<MdIndex> findByIds(List<String> idIndex, Integer euTp, Byte fgAccu) {
        if(idIndex==null || idIndex.size()==0) {
            return null;
        }
        return mdIndexMapper.findByIds(idIndex,euTp,fgAccu);
    }

    @Override
    public List<MdIndex> selectNotInDm(MdIndex mdIndex) {
        return mdIndexMapper.selectNotInDm(mdIndex);
    }

    @Override
    public List<MdIndex> selectIndexWall(IndexWallParamVO mdIndex) {
        return mdIndexMapper.selectIndexWall(mdIndex);
    }

    @Override
    public List<MdIndex> selectMdIndexListByIdLabels(MdIndexParamVO paramVO) {
        if(paramVO.getIdLabels()==null || paramVO.getIdLabels().size()==0) {
            paramVO.setIdLabels(null);
        } else {
            paramVO.setSize(paramVO.getIdLabels().size());
        }
        return mdIndexMapper.selectMdIndexListByIdLabels(paramVO);
    }

    @Override
    public List<MdIndex> selectIndexByCdLabel(String cdLabel) {
        return mdIndexMapper.selectIndexByCdLabel(cdLabel);
    }
}
